﻿var isValid = true;
var msgBox = null;
var t = null;
var swfu="";
$(function () {
    $('.window-mask').css('width', '100%');
    $(".textbox-prompt").css('background-color', '#6D6666');
    $(".filebox").css('background-color', '#6D6666');
    $('.l-btn-left').css('background-color', '#6D6666');
    $('.l-btn-text').text('').append('<img src="../images/u286.gif"/ style="margin-bottom: 4px;border:0px;">');
    msgBox = new MsgBox({ imghref: "../images/" });
    $('input[id=btnYanZ]').click(GetCheck);
    $('input[id=btnSuInfo]').click(GetSuccessInfo);
    $('a[title=详细积分]').click(GetScoreList);
    $('input[id=btnSure]').click(GetMiBao);
    var userName = $("#UserNameManager").val();
    if (userName != "admin") {
        $("li a[name=word]").hide();
        var strHtml = '<li><a href="../View/UserManageCenter.aspx?userList=3">地址簿管理</a></li>' +
                      '<li><a href="../View/UserManageCenter.aspx?userList=4">我的积分</a></li>' +
                      '<li><a href="../View/UserManageCenter.aspx?userList=5">密保问题</a></li>';
        $('.content1 ul').append(strHtml);
    } else
    {
        $("li a[name=word]").show();
    }
    $('input[id=btndialogOk]').bind('click', function () {
        if (GetComPwd())
        {
            $('#_dialogModify').dialog('close');
        }
    });
 GetUpPhoto();
});
function ShowInfo(msg,info,statu)
{
    if (msg == 'true') {
        $(".easyui-filebox").filebox('setValue', "");
        if (statu == 1) {
            $("#txtContent").val("");
            info = info.replace(/,/g, "\r\n");
            $("#txtContent").val(info);
            $("#txtContent").css('color', '#fff');
        } else
        {
            msgBox.showMsgOk(info);
        }
    } else
    {
        msgBox.showMsgErr(info);
    }
}
function doAddressDel(id, btn)
{
    $.post("../Action/UserManageCenter.ashx", { type: "del", id: id}, function (jsObj) {
        if (jsObj.statu == "ok") {
            $(btn).parent().parent().remove();
            msgBox.showMsgOk(jsObj.msg);
        }
    }, "json");
}

function GetCheck()
{
    var username = $("#txtName").val();
    var pwd = $("#txtPwd").val();
    $("#userId").val(username);
    $.post("../Action/UserManageCenter.ashx", { type: "check", username: username ,pwd:pwd}, function (jsObj) {
        if (jsObj.statu == "ok") {
            msgBox.showMsgOk(jsObj.msg);
            $("#_dialogModify").dialog("open");
            $("#txtPwd").val("");
            $("#txtPwd1").val("");
        } else
        {
            msgBox.showMsgErr(jsObj.msg);
        }
    }, "json");

}

function GetSuccessInfo()
{
    if (!checkMobile($("#txtPhone").val()))
    {
        msgBox.showMsgOk("手机格式书写有误！~~");
        return;
    }
    if (!checkEmail($("#txtEmail").val()))
    {
        msgBox.showMsgOk("邮箱格式书写有误！~~");
        return;
    }
    var data =$("#fSInfo").serialize();
    $.post("../Action/UserManageCenter.ashx",data+"&type=successInfo",function(jsObj){
        if(jsObj.statu=="ok")
        {
            msgBox.showMsgOk(jsObj.msg);
        }
    },"json");

}
function GetMiBao() {
    var data = $("#fSInfoMobao").serialize();
    $.post("../Action/UserManageCenter.ashx", data + "&type=MiBaoInfo", function (jsObj) {
        if (jsObj.statu == "ok") {
            msgBox.showMsgOk(jsObj.msg);
        }
    }, "json");

}

function GetComPwd()
{
    if ($("#txtPwd1").val().trim() == "")
    {
        msgBox.showMsgErr("新密码不能为空");
        return false;
    } else if ($("#txtPwd1").val().trim() != $("#txtComPwd").val().trim()) {
        msgBox.showMsgErr("两次密码不一致！");
        return false;
    }
    var data = $("#fModify").serialize();
    $.post("../Action/UserManageCenter.ashx", data + "&type=checkpwd", function (jsObj) {
        debugger;
        if (jsObj.statu == "err")
        {
            msgBox.showMsgOk(jsObj.msg);
            return;
        } else if (jsObj.statu == "ok")
        {
            msgBox.showMsgOk(jsObj.msg);
            window.open(jsObj.data);
        }
    }, "json");
    return true;
}

function GetScoreList()
{
    $.post("../Action/UserManageCenter.ashx", { type: "score" }, function (jsObj) {
        if (jsObj.statu == "ok")
        {
            var strLi = "";
            var table = '<table id="tbList" style="width:80%;"><tr id="trNav"><th colspan="2">用户【' + $("#score").val() + '】的积分列表</th></tr><tr><th style=\"width:50%;\">积分获取时间</th><th style=\"width:50%;\">积分</th></tr>';
            for (var i = 0; i < jsObj.data.length; i++)
            {
                var strData = jsObj.data[i].OrderDate.split('T');
                jsObj.data[i].OrderDate = strData[0];
                strLi += '<tr><td>' + jsObj.data[i].OrderDate + '</td><td>' +parseFloat(jsObj.data[i].TotalPrice) + '</td></tr>';
            }
            var table1 = '</table>';
            $("#scoreList").html("").html(table + strLi + table1);
        }
    }, "json");
}
function GetUpPhoto()
{
    swfu = new SWFUpload({
        // Backend Settings
        // 上传请求处理地址
        upload_url: "UserManageCenter.aspx",
        // POST提交同时伴随上传的键值对
        post_params: {
           // "ASPSESSID": "<%=Session.SessionID %>"
           },

        // File Upload Settings
        // 最大文件限制
        file_size_limit: "2 MB",
        // 上传文件类型
        file_types: "*.jpg",
        file_types_description: "JPG Images",
        file_upload_limit: 0,    // Zero means unlimited

        // Event Handler Settings - these functions as defined in Handlers.js
        //  The handlers are not part of SWFUpload but are part of my website and control how
        //  my website reacts to the SWFUpload events.
        swfupload_preload_handler: preLoad,
        //swfupload_load_failed_handler: loadFailed,
        file_queue_error_handler: fileQueueError,
        file_dialog_complete_handler: fileDialogComplete,
        upload_progress_handler: uploadProgress,
        upload_error_handler: uploadError,
        upload_success_handler: function (file, serverData) {
            debugger;
            $('#img').removeAttr("src").attr("src",serverData);
            $("#divFileProgressContainer").html("").show();
            setInterval(function () {
                $("#divFileProgressContainer").hide();
            }, 5000);
        },
        upload_complete_handler: uploadComplete,

        // Button settings
        button_image_url: "../assets/lib/swfupload/images/XPButtonNoText_160x22.png",
        button_placeholder_id: "spanButtonPlaceholder",
        button_width: 80,
        button_height: 22,
        button_text: '<span class="button">上传图片 <span class="buttonSmall"></span></span>',
        button_text_style: '.button { font-family: Helvetica, Arial, sans-serif; font-size: 14pt; } .buttonSmall { font-size: 10pt; }',
        button_text_top_padding: 1,
        button_text_left_padding: 5,

        // Flash Settings
        flash_url: "../assets/lib/swfupload/swfupload.swf",	// Relative to this file
        flash9_url: "../assets/lib/swfupload/swfupload_FP9.swf",	// Relative to this file

        custom_settings: {
            upload_target: "divFileProgressContainer"
        },

        // Debug Settings
        debug: false
    });
}
